<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh">

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<head>
 <base href="<%=basePath%>">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="format-detection" content="telephone=no">
  <meta name="format-detection" content="email=no">
  <title>补充描述</title>
  <link href="http://cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet">
<link href="static/css/style.css" rel="stylesheet"></head>

<body>
  <div class="content content-refund">
    <div class="wrapper">
      <!-- 问题描述 -->
      <div class="problem bgwh pb20 ui-1px-b">
        <p class="f28 pl20 pt20 pb20">问题描述 </p>
        <div class="textarea rel">
        <form enctype="multipart/form-data" method="post" id="refundform">
          <input type="hidden" name="code" value="${asn.code}" id="code">
          <textarea name="asq.content" id="content" class="textarea__style f24 on-textarea" rows="8" placeholder="请您在此描述问题"></textarea>
         </form> 
          <span class="tips-number abs f22 g9 on-textarea-limit" data-limit="500">0</span>
        </div>
        <!-- 上传图片 -->
        <div class="update-list mt20 f0 pl20 pr20 pt10">
          <label class="update-item update-default dib vm on-update-pic" for="update-file">
              <input class="update-file" id="update-file" type="file"  accept="image/png,image/jpeg,image/jpg">
            </label>
        </div>
      </div>
      <!-- 提示 -->
      <p class="point-info g6 mt20 tc">
        <span class="icon-information dib vm ml20"></span>
        <span class="f22 dib vm">提交退款信息后，售后专员可能与您电话联系，请保持手机畅通</span>
      </p>
      <div class="mt20 mb20 pb20 pb20"></div>
      <div class="tc mt20">
        <a class="btn btn__primary f32 white ml20 mr20 db" id="submit-btn" href="javascript:;">提交</a>
      </div>
      <div class="mt20 mb20 pb20 pb20"></div>
    </div>
  </div>
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="static/js/lib/layer_mobile/layer.js"></script>
  <script>

      var files,type;
      $('#submit-btn').on("click", function () {
    	var code = $('#code').val();
    	//判断参数
    	var content = $.trim($('#content').val());
    	if(content == ''){
    		layer.open({
    		    content: '请输入问题描述'
    		    ,btn: '我知道了'
    		  });
    		return;
    	}
    	
        files = [];
        getBase64(files)
        var formobj =  document.getElementById("refundform");
        var formData = new FormData(formobj);
        
        $.each(files,function(i,file){
        	formData.append("imgs",file);
        }); 
        console.log(files);
       var load = layer.open({type: 2,shadeClose:false});
        $.ajax({
        	  url: "wap/order/refund/question/add",
        	  type: "POST",
        	  data: formData,
        	  processData: false,  
        	  contentType: false,
        	  success : function(data) {
        		  var state = data.result.state;
        		  layer.close(load);
        		  if(state == 1){
        			 layer.open({
        				    title: '提示',
        				    content: data.result.message,
        				    btn: ['我知道了'],
        				    yes: function(index){
 				    			location.href="wap/order/refund/detail?code="+code;
 				    		}
        			});
        		  }else{
        			
      				layer.open({
      				    title: '提示',
      				    content: data.result.message,
      				    btn: ['我知道了']
      				});
        		  }
        	  }
        	});
      
      })


    function getBase64(files) {
      var items = document.querySelectorAll('.update-item')
      for (var i = 0; i < items.length - 1; i++) {
        var oImg = items[i].querySelector('img')
        var base64 = oImg.src;
        files.push(blobFile(base64))
      }
    }

    function blobFile(base64) {
      var baseArr = base64.split(",");
      var fileType = baseArr[0].match(/:(.*?);/)[1];
      var cont = atob(baseArr[1]);
      var n = cont.length;
      var u8Arr = new Uint8Array(n);
      var blob;
      while (n--) {
        u8Arr[n] = cont.charCodeAt(n);
      }
      blob = new Blob([u8Arr], { type: fileType });
      return blob;
    }
  </script>
<script type="text/javascript" src="static/js/lib/vendor.js"></script><script type="text/javascript" src="static/js/lib/app.js"></script></body>

</html>

